package com.lmqb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmqb.bean.LmFeedback;
import com.lmqb.bean.LmInnerMessage;
import com.lmqb.bean.LmSmsCode;
import com.lmqb.bean.LmUser;
import com.lmqb.bean.SysActivity;
import com.lmqb.bean.SysBlack;
import com.lmqb.bean.SysNotice;
import com.lmqb.bean.SysQuestion;
import com.lmqb.bean.SysUser;
import com.lmqb.dao.LmFeedbackMapper;
import com.lmqb.dao.LmInnerMessageMapper;
import com.lmqb.dao.LmSmsCodeMapper;
import com.lmqb.dao.LmUserMapper;
import com.lmqb.dao.SysActivityMapper;
import com.lmqb.dao.SysNoticeMapper;
import com.lmqb.dao.SysQuestionMapper;
import com.lmqb.dao.SysUserMapper;
import com.lmqb.page.ActivePager;
import com.lmqb.page.FeedbackPager;
import com.lmqb.page.InnerMsgPager;
import com.lmqb.page.NoticePager;
import com.lmqb.page.PageTool;
import com.lmqb.page.QuestionPager;
import com.lmqb.page.SmsCodePager;
import com.lmqb.service.MsgService;
import com.lmqb.util.StrUtil;
@Service("msgService")
public class MsgServiceImpl implements MsgService{

	@Autowired
	private SysNoticeMapper noticeDao;
	
	@Autowired
	private SysActivityMapper activeDao;
	
	@Autowired
	private SysQuestionMapper questionDao;
	
	@Autowired
	private LmInnerMessageMapper innerMsgDao;
	
	@Autowired
	private LmFeedbackMapper feedbackDao;
	
	@Autowired
	private LmUserMapper lmUserDao;
	
	@Autowired
	private LmSmsCodeMapper smsCodeDao;
	
	@Autowired
	private SysUserMapper sysUserDao;
	
	//消息公告列表
	public NoticePager selectNoticePager(NoticePager pagerModel) {
		List<SysNotice> list=noticeDao.selectAll(pagerModel);
//		List<SysUser> admins=sysUserDao.selectAllUser();
		for(int i=0;i<list.size();i++){
			list.get(i).setCreateTimeD(StrUtil.intToTime(list.get(i).getCreateTime()));
			list.get(i).setPublishTimeD(StrUtil.intToTime(list.get(i).getPublishTime()));
			list.get(i).setLastModifyTimeD(StrUtil.intToTime(list.get(i).getLastModifyTime()));
//			for(int j=0;j<admins.size();j++){
//				if(admins.get(j).getUserId()==list.get(i).getAdminId()){
//					list.get(i).setAdminName(admins.get(j).getLoginName());
//				}
//			}
		}
		pagerModel.setList(list);
		int count = noticeDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}
	//添加消息公告
	public int addSmg(SysNotice sysNotice){
		
		return noticeDao.insert(sysNotice);
	}
	
	//消息公告回显
	public  SysNotice selectByPrimaryKey(Integer noticeId){
		
		
		return noticeDao.selectByPrimaryKey(noticeId);
		};
    //显示作者名字
	public	SysUser selectById(Integer userId){
		
		return sysUserDao.selectByPrimaryKey(userId);
		
	}
	
	
	//消息广告修改
	public int updateByPrimaryKeySelective(SysNotice record){
		return noticeDao.updateByPrimaryKeySelective(record);
		
	}

	//热门活动列表
	public ActivePager selectActivePager(ActivePager pagerModel) {
		List<SysActivity> list=activeDao.selectAll(pagerModel);
		List<SysUser> admins=sysUserDao.selectAllUser();
		for(int i=0;i<list.size();i++){
			list.get(i).setCreateTimeD(StrUtil.intToTime(list.get(i).getCreateTime()));
			list.get(i).setPublishTimeD(StrUtil.intToTime(list.get(i).getPublishTime()));
			list.get(i).setLastModifyTimeD(StrUtil.intToTime(list.get(i).getLastModifyTime()));
			for(int j=0;j<admins.size();j++){
				if(admins.get(j).getUserId()==list.get(i).getAdminId()){
					list.get(i).setAdminName(admins.get(j).getLoginName());
				}
			}
		}
		pagerModel.setList(list);
		int count = activeDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}
	//添加热门活动
	public int addActive(SysActivity sysActivity){
		int insert = activeDao.insert(sysActivity);
		return insert;
		
	}

	//@Override
	public QuestionPager selectQuestionPager(QuestionPager pagerModel) {
		List<SysQuestion> list=questionDao.selectAll(pagerModel);
		for(int i=0;i<list.size();i++){
			list.get(i).setCreateTimeD(StrUtil.intToTime(list.get(i).getCreateTime()));
			list.get(i).setLastModifyTimeD(StrUtil.intToTime(list.get(i).getLastModifyTime()));
		}
		pagerModel.setList(list);
		int count = questionDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}

	//@Override
	public InnerMsgPager selectInnerMsgPager(InnerMsgPager pagerModel) {
		List<LmInnerMessage> list=innerMsgDao.selectAll(pagerModel);
		List<LmUser> userList=lmUserDao.selectAllUser();
		for(int i=0;i<list.size();i++){
			list.get(i).setCreateTimeD(StrUtil.intToTime(list.get(i).getCreateTime()));
			list.get(i).setDeleteTimeD(StrUtil.intToTime(list.get(i).getDeleteTime()));
			list.get(i).setReadTimeD(StrUtil.intToTime(list.get(i).getReadTime()));
			for(int j=0;j<userList.size();j++){
				if(list.get(i).getUserId().intValue()==userList.get(j).getUserId().intValue()){
					list.get(i).setUserName(userList.get(j).getLoginMobile());
					break;
				}
			}
		}
		pagerModel.setList(list);
		int count = innerMsgDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}

	//@Override
	public FeedbackPager selectFeedBackPager(FeedbackPager pagerModel) {
		List<LmFeedback> list=feedbackDao.selectAll(pagerModel);
//		List<LmUser> userList=lmUserDao.selectAllUser();
		for(int i=0;i<list.size();i++){
			list.get(i).setCreateTimeD(StrUtil.intToTime(list.get(i).getCreateTime()));
			list.get(i).setLastModifyTimeD(StrUtil.intToTime(list.get(i).getLastModifyTime()));
//			for(int j=0;j<userList.size();j++){
//				if(list.get(i).getUserId()==userList.get(j).getUserId()){
//					list.get(i).setUserName(userList.get(j).getLoanMobile());
//					break;
//				}
//			}
		}
		pagerModel.setList(list);
		int count = feedbackDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}

	//@Override
	public SmsCodePager selectSmsCodePager(SmsCodePager pagerModel) {
		List<LmSmsCode> list=smsCodeDao.selectAll(pagerModel);
		for(int i=0;i<list.size();i++){
			list.get(i).setCreateTimeD(StrUtil.intToTime(list.get(i).getCreateTime()));
			list.get(i).setExpireTimeD(StrUtil.intToTime(list.get(i).getExpireTime()));
			list.get(i).setSendTimeD(StrUtil.intToTime(list.get(i).getSendTime()));
			list.get(i).setUsedTimeD(StrUtil.intToTime(list.get(i).getUsedTime()));
		}
		pagerModel.setList(list);
		int count = smsCodeDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}
	//热门活动回显
	public SysActivity selectActiveByPrimaryKey(Integer activityId) {
		SysActivity active = activeDao.selectByPrimaryKey(activityId);
		return active;
	}
	//热门活动修改
	public int updateActiveByPrimaryKey(SysActivity record) {
		int i = activeDao.updateByPrimaryKey(record);
		return i;
	}
	
	//修改热门活动图片
	public int updateByPrimaryKeySelectiveP(SysActivity record) {
			System.out.println("service------"+record);
		return activeDao.updateByPrimaryKeySelective(record);
	}
	//删除消息公告
	public int deleteByPrimaryKey(Integer noticeId) {
		int i = noticeDao.deleteByPrimaryKey(noticeId);
		return i;
	}
	//删除热门活动
	public int deleteByPrimaryKeyA(Integer activityId) {
		int i = activeDao.deleteByPrimaryKey(activityId);
		return i;
	}
	//删除意见反馈
	public int deleteByPrimaryKeyF(Integer feedbackId) {
		
		return feedbackDao.deleteByPrimaryKey(feedbackId);
	}
	//修改意见反馈状态
	public int updateStatusById(Integer feedbackId) {
		
		return feedbackDao.updateStatusById(feedbackId);
	}
	
	
	
}
